{include file="admin/head" /}

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">器具管理</a>
        <a>
          <cite>器具列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div style="padding: 20px">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" method="get" action="">
            <input type="text" name="name" placeholder="请输入器具名称" autocomplete="off" class="layui-input">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    {if $Think.session.admin}
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('添加用户','{:url('tool_add')}')"><i class="layui-icon"></i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：{$tools|count} 条</span>
    </xblock>
    {/if}
    <table class="layui-table">
        <thead>
        <tr>
            {if $Think.session.admin}
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            {/if}
            <th>ID</th>
            <th>器具名称</th>
            <th>所属科室</th>
            <th>所属教师</th>
            <th>最大借出天</th>
            <th>器具类型</th>
            <th>状态</th>
            {if $Think.session.admin}
            <th>操作</th>
            {/if}

        </thead>
        <tbody>
        {volist name="tools" id="tool"}
        <tr>
            {if $Think.session.admin}
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$tool.id}'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            {/if}

            <td>{$tool.id}</td>
            <td>{$tool.name}</td>
            <td>{$tool->lab->name|default="暂无实验室信息"}</td>
            <td>{$tool->lab->teacher->realname|default="暂无教师姓名"}</td>
            <td>{$tool.num}</td>
            <td>
                {$tool.type?'大型器具':'小型器具'}
            </td>
            <td class="td-status">
                {switch $tool.statu}
                    {case 0} <button id="btn" class="layui-btn layui-btn-xs layui-btn-normal">在库</button>{/case}
                    {case 1} <button id="btn" class="layui-btn layui-btn-xs layui-btn-danger">借出</button>{/case}
                    {case 2} <button id="btn" class="layui-btn layui-btn-xs layui-btn-disabled">损坏</button>{/case}
                {/switch}
            </td>
            {if $Think.session.admin}
            <td class="td-manage">
                {eq name="$tool.statu" value="0"}
                <a title="设为损坏" onclick="change_statu(this,'{$tool.id}')" href="javascript:;">
                    <i class="layui-icon ">&#xe631;</i>
                </a>
                {/eq}
                <a title="编辑" onclick="x_admin_show('编辑','{:url('tool_update')}/id/{$tool.id}')" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="member_del(this,'{$tool.id}')" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
            {/if}
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page">
        {$tools|raw}
    </div>
</div>
<script>
    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.post(
                "{:url('tool_dele')}",
                {id: id},
                function (data) {
                    if (data.statu == 200) {
                        $(obj).parents("tr").remove();
                        layer.msg(data.msg, {icon: 1, time: 1000});
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1000});
                    }
                }
            )

        });
    }

    function change_statu(obj,id){
        layer.confirm('确定要将此器具设为损坏？',function(index){
            $.post(
                "{:url('tool_disable')}",
                {id:id},
                function(data){
                    if (data.statu==200) {
                        layer.msg(data.msg,{icon: 1,time:1000});
                        $(obj).parents("tr").find(".td-status").find('#btn').addClass('layui-btn-disabled').html('损坏');
                        $(obj).hide();
                    }else{
                        layer.msg(data.msg,{icon: 2,time:1000});
                    }
                }
                )
        })
    }

    function delAll(argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？' + data, function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post(
                "{:url('lab_dele')}",
                {id: data},
                function (data) {
                    if (data.statu == 200) {
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                        layer.msg(data.msg, {icon: 1, time: 1000});
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 1000});
                    }
                }
            )
        });
    }
</script>
</body>
</html>